package com.example.demo.service;


import com.alibaba.excel.EasyExcel;
import com.example.demo.pojo.Student;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.time.LocalDateTime;
import java.util.List;

@Configuration
@EnableScheduling
public class ScheduleService {



    @Mapper
    public interface GetStudentMapper{
        @Select("SELECT * FROM student")
        public List<Student> getAll();
    }

    @Autowired
    GetStudentMapper getStudentMapper;


    //日报
    @Scheduled(cron = "0 0 0,12 * * ?")
    private void  configureTasks(){
        String filename = "D:\\桌面\\期末作业\\student.xlsx";
        EasyExcel.write(filename, Student.class).sheet("学生信息表").doWrite(getStudentMapper.getAll());
    }


    //周报
    @Scheduled(cron = "0 0 0 ? * MON ")
    private void  configureTasks1(){
        String filename = "D:\\桌面\\期末作业\\student.xlsx";
        EasyExcel.write(filename, Student.class).sheet("学生信息表").doWrite(getStudentMapper.getAll());
    }

    //月报
    @Scheduled(cron = "0 0 0 1 * ?")
    private void  configureTasks2(){
        String filename = "D:\\桌面\\期末作业\\student.xlsx";
        EasyExcel.write(filename, Student.class).sheet("学生信息表").doWrite(getStudentMapper.getAll());
    }





}
